<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="page">
<body>
<div th:fragment="pager">
    <div class="text-right" th:with="baseUrl=${#httpServletRequest.getRequestURL().toString()},pars=${#httpServletRequest.getQueryString() eq null ? '' : new String(#httpServletRequest.getQueryString().getBytes('iso8859-1'), 'UTF-8')}">
        <ul style="margin:0px;" class="pagination" th:with="newPar=${new java.lang.String(pars eq null ? '' : pars).replace('page='+(users.number), '')},
                                                pageTmpUrl=${baseUrl+'?'+newPar},
                                                pageUrl=${pageTmpUrl.endsWith('&amp;') ? pageTmpUrl.substring(0, pageTmpUrl.length()-1):pageTmpUrl}">
            <li><a href="#" th:href="@{${pageUrl}(page=0)}">首页</a></li>
            <li th:if="${users.hasPrevious()}"><a href="#" th:href="@{${pageUrl}(page=${users.number-1})}">上一页</a></li>
            <!--总页数小于等于10-->
            <div th:if="${(users.totalPages le 10) and (users.totalPages ge 0)}" th:remove="tag">
                <div th:each="pg : ${#numbers.sequence(0,users.totalPages - 1)}" th:remove="tag">
                    <span th:if="${pg eq users.getNumber()}" th:remove="tag">
                        <li class="active"><span class="current_page line_height" th:text="${pg+1}">${pageNumber}</span> </li>
                    </span>
                    <span th:unless="${pg eq users.getNumber()}" th:remove="tag">
                        <li><a href="#" th:href="@{${pageUrl}(page=${pg})}"></a> </li>
                    </span>
                </div>
            </div>
            <!--总数大于10时-->
            <div th:if="${users.totalPages ge 10}" th:remove="tag">
                <li th:if="${users.number-2 ge 0}"><a href="#" th:href="@{${pageUrl}(page=${users.number}-2)}" th:text="${users.number-1}"></a> </li>
                <li th:if="${users.number-1 ge 0}"><a href="#" th:href="@{${pageUrl}(page=${users.number}-1)}" th:text="${users.number}"></a> </li>
                <li class="active"><span class="current_page line_height" th:text="${users.number+1}"></span></li>
                <li th:if="${users.number+1 lt users.totalPages}"><a href="#" th:href="@{${pageUrl}(page=${users.number}+1)}" th:text="${users.number+2}"></a> </li>
                <li th:if="${users.number+2 lt users.totalPages}"><a href="#" th:href="@{${pageUrl}(page=${users.number}+2)}" th:text="${users.number+3}"></a> </li>
            </div>

            <li th:if="${users.hasNext()}"><a href="#" th:href="@{${pageUrl}(page=${users.number+1})">下一页</a> </li>
            <li><a href="#" th:href="${users.totalPages le 0 ? pageUrl+'page=0':pageUrl + '&amp;page='+(users.totalPages-1)}">尾页</a> </li>
            <li><span th:utext="'共'+${users.totalPages}+'页／'+${users.totalElements}+'条'"></span> </li>
        </ul>
    </div>
</div>
</body>
</html>